package com.moleq.service;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.moleq.db.DatabaseHelper;
import com.moleq.models.CustomerSetting;
import com.moleq.models.GlobalInfo;
import com.moleq.models.States;

public class StatesService {
	private DatabaseHelper DBHelper;
	private Context mContext;
	public StatesService() {
		
	}
	public StatesService(Context context){
		mContext = context;
		this.DBHelper = new DatabaseHelper(GlobalInfo.getInstance().ShareContext);
	}
	
	public List<States> getStates(){
		List<States> list = new ArrayList<States>();
		String sql = "select * from t_states";
		SQLiteDatabase db = DBHelper.getWritableDatabase();
		Cursor cursor = db.rawQuery(sql, null);
//		Cursor cursor = dbHelper.select(sql);
		if(cursor == null) return null;
		while(cursor.moveToNext()){
			States item = new States();
			item.setState_id(cursor.getString(0));
			item.setState_name(cursor.getString(1));
			list.add(item);
		}
		cursor.close();
		return list;
	}
	public List<States> getStatesById(String Id){
		List<States> list = new ArrayList<States>();
		String sql = "select * from t_states where state_id like '" + Id + "%'";
		SQLiteDatabase db = DBHelper.getWritableDatabase();
		Cursor cursor = db.rawQuery(sql, null);
//		Cursor cursor = dbHelper.select(sql);
		if(cursor == null) return null;
		while(cursor.moveToNext()){
			States item = new States();
			item.setState_id(cursor.getString(0));
			item.setState_name(cursor.getString(1));
			list.add(item);
		}
		cursor.close();
		return list;
	}
}
